< previous page page_966 next page >

Page 966
9. The Index data object can be used to contain information on Microsoft Jet databases only.
10. The QueryDef object stores Structure Query Language (SQL) statements. A QueryDef is faster than an actual SQL statement because Visual Basic has to perform an additional preprocessing step for an SQL statement, which it does not need to perform for the QueryDef.
Answer to Day 9 Exercise
Drop a command button onto a form, name it cmdCreate, and enter the following code:
Private Sub cmdCreate_Click()

    On Error Resume Next

    'Define Variables
    Dim dbFile As DATABASE
    Dim cDBName As String
    Dim tdTemp As TableDef
    Dim fldTemp As Field
    Dim idxTemp As Index
    Dim relTemp As Relation
    Dim ctblCustomers As String
    Dim ctblCustomerTypes As String
    Dim cidxCustomers As String
    Dim cidxCustomerTypes As String
    Dim crelName As String

    'Set variables
    cDBName = App.Path + "\10ABCEX.MDB"
    ctblCustomers = "Customers"
    ctblCustomerTypes = "CustomerTypes"
    cidxCustomers = "PKCustomers"
    cidxCustomerTypes = "PKCustomerTypes"
    crelName = "relCustomerType"

    'Delete the database if it already exists
    Kill cDBName

    'Create the database
    Set dbFile = CreateDatabase(cDBName, dbLangGeneral, dbVersion20)

    'Create the Customers table
    Set tdTemp = dbFile.CreateTableDef(ctblCustomers)

    'Insert fields into the Customers table
    Set fldTemp = tdTemp.CreateField("CustomerID", dbText, 10)
    tdTemp.Fields.Append fldTemp
 Set fldTemp = tdTemp.CreateField("Name", dbText, 50)
    tdTemp.Fields.Append fldTemp
    Set fldTemp = tdTemp.CreateField("Address1", dbText, 50)
    tdTemp.Fields.Append fldTemp
    Set fldTemp = tdTemp.CreateField("Address2", dbText, 50)
    tdTemp.Fields.Append fldTemp

 
< previous page page_966 next page >

If you like this book, buy it!